#!/usr/bin/env python
# encoding: utf-8
"""
@author: youfeng
@email: youfeng243@163.com
@license: Apache Licence
@file: copy_zhejiang_company.py
@time: 2018/1/2 10:43
"""

import sys

sys.path.append('..')
sys.path.append('../..')

from common import util
from common.mongo import MongDb
from logger import Logger

MONGO_DB_SOURCE = {
    'host': '172.16.215.2',
    'port': 40042,
    'db': 'company_data',
    'username': 'work',
    'password': 'haizhi'
}

# 日志模块
log = Logger('insert_keyword_to_zhejiang.log').get_logger()

source_db = MongDb(MONGO_DB_SOURCE['host'], MONGO_DB_SOURCE['port'], MONGO_DB_SOURCE['db'],
                   MONGO_DB_SOURCE['username'],
                   MONGO_DB_SOURCE['password'], log=log)


def main():
    source_table_name = 'zhejiang_keyword'
    result_list = []
    with open('keyword.txt') as p_file:
        for line in p_file:
            key_word = line.strip('\n').strip('\r')
            param = {
                '_id': key_word,
                'crawl_status': 0,
                '_in_time': util.get_now_time(),
            }
            result_list.append(param)

        source_db.insert_batch_data(source_table_name, result_list)


if __name__ == '__main__':
    main()
